<template>
  
  <el-container class="home-container">
    <!-- 这是头部 -->
  <el-header>
    <div>
      <img src="../assets/logo.png" alt="">
      <span>后台管理</span>
    </div>
      <el-button type="info" @click="logout">退出</el-button>
  </el-header>
  <el-container>
    <!-- 这是侧边 -->
    <el-aside :width="isCollapse ? '64px':'200px'">
      <div class="collapse" @click="toggleCollapse">|||</div>
      <el-menu
      default-active="2"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      background-color="rgb(179,192,209)"
      text-color="#fff"
      active-text-color="rgb(65,184,131)" :unique-opened="true" :collapse="isCollapse" 
      :collapse-transition=false :router=true :default-active=$route.path>
      <el-submenu :index="item.id+''" v-for="item in menulist" :key="item.id" >
        <template slot="title">
          <i :class="menuObj[item.id]"></i>
          <span>{{item.authName}}</span>
        </template>
          <el-menu-item  :index="'/'+subItem.path" 
          v-for="subItem in item.children" :key="subItem.id">
            <i class="el-icon-menu"></i>
          <span>{{subItem.authName}}</span>
          </el-menu-item>
      </el-submenu>
      
    </el-menu>
    </el-aside>
    <!-- 这是主要 -->
    <el-main>
      <router-view>
        <!-- 这是路由 -->
      </router-view>
    </el-main>
  </el-container>
</el-container>
</template>

<script>
export default {
    name:"home",
    data(){
        return{
          menulist:[],
          menuObj:{
            '125':'el-icon-s-check',
            '103':'el-icon-warning',
            '101':'el-icon-s-goods',
            '102':'el-icon-s-finance',
            '145':'el-icon-s-platform'
          },
          isCollapse:false
          // activepath:''
          
        }
        
    },
    created(){
      this.getMenuList()
      
    },
    methods:{
      logout(){
        window.sessionStorage.clear();
        this.$router.push('/login');
      },
      async getMenuList(){
        const {data:res}= await this.$http.get('menus')
        if(res.meta.status!==200)return this.$message.error(res.meta.msg)
        this.menulist=res.data
        console.log(res)
      },
      toggleCollapse(){
        this.isCollapse=! this.isCollapse
        console.log(this.isCollapse)
      }
      // consolepath(){
      //   this.$message.success('现在在'+this.$route.path)
      // }
      // Dactivepath(activepath){
      //   window.sessionStorage.setItem('activepath',activepath)
      //   this.activepath=window.sessionStorage.getItem('activepath')
      //   console.log(this.activepath)
      // }

      
    }
}
</script>

<style lang="less" scoped>
.home-container{
  height: 100%;
}
.el-header{
  background-color: rgb(179,192,209);
  display: flex;
  justify-content: space-between;
  padding-left: 0;
  align-items: center;//按钮中间对齐
  color: #fff;
  font-size: 20px;
  
  >div{
    display: flex;
    align-items: center;
    span{
      margin-left: 10px;
    }
  }
  img{
    height: 60px;
    width: 60px;
  }
}
.el-aside{
  background-color: rgb(179,192,209);
  .el-menu{
    border-right: none;
  }
  .collapse{
    line-height: 24px;
    color: #fff;
    text-align: center;
    background-color: rgb(166,169,173);
    letter-spacing: 0.2em;
    cursor: pointer;
    font-size: 10px;
  }
}
.el-main{
  background-color: rgb(233,238,243);
}
</style>
